use std::ffi::CString;
use ash::vk;

use super::utils_ffi::*;
use crate::VK_LOGV;

/// supported_extension_properties是API Query出来支持的List
/// 和required_extension_names输出对比
pub fn display_extension(
    required_extension_names: &Vec<CString>, 
    supported_extension_properties: &Vec<vk::ExtensionProperties>, 
    required_extension_text: &'static str,
    supported_extension_text: &'static str,
) {
    VK_LOGV!("{}: {}", supported_extension_text, supported_extension_properties.len());
    for properties in supported_extension_properties {
        let extension_name      = i8_2_str(&properties.extension_name);
        VK_LOGV!("    {:50} v.{}", extension_name, properties.spec_version);
    }

    VK_LOGV!("{}: {}", required_extension_text, required_extension_names.len());
    for required_extension_name in required_extension_names {
        let extension_name_str = i8_ptr_2_str(&required_extension_name.as_ptr());
        VK_LOGV!("    {:50}", extension_name_str);
    }
}

/// extension_properties是API Query出来的List
/// 筛选required_extension_names是不是都支持
pub fn get_unsupported_extension(
    required_extension_names: &Vec<CString>, 
    extension_properties: &Vec<vk::ExtensionProperties>
) -> Vec<String> {
    let unsupported_extension_names: Vec<String> = required_extension_names
        .iter()
        .map(|required_extension_name| String::from_utf8(required_extension_name.to_bytes().to_vec()).unwrap())
        .filter(|required_extension_name|
            !extension_properties
                .iter()
                .any(|supported_layer_properties|
                    i8_2_string(&supported_layer_properties.extension_name)
                        .eq(required_extension_name)
                )
        ).collect();

    unsupported_extension_names
}